/*
	weak_type_value.h
	@author:Wolfhead
*/
#ifndef WOLV_WEAK_TYPE_VALUE_H
#define WOLV_WEAK_TYPE_VALUE_H


#include <string>

#include "weak_type_define.h"


namespace wolv
{

namespace weakType
{

namespace _detail
{
	class weakTypeHolder;
}

#define REGION_OPERATION_START ("start")
#define REGION_OPERATION_END ("end")

class Value
{
public:

	static std::string TypeName(valueType type);

	Value();
	virtual ~Value();

	Value(valueType type);
	Value(int value);
	Value(bool value);
	Value(double value);
	Value(const char* value);
	Value(const Value& value);

	Value& operator= (const Value& value);
	Value& operator= (valueType type);
	Value& operator= (int value);
	Value& operator= (bool value);
	Value& operator= (double value);
	Value& operator= (const char* value);
	Value& operator= (const std::string& value);

	const Value& operator[] (unsigned int index) const;
	const Value& operator[] (const char* key) const;
	const Value& operator[] (const std::string& key) const;
	
	Value& operator[] (unsigned int index);
	Value& operator[] (const char* key);
	Value& operator[] (const std::string& key);

	bool operator==(const Value& value);
	bool operator!=(const Value& value);
	bool operator>(const Value& value);
	bool operator<(const Value& value);
	bool operator>=(const Value& value);
	bool operator<=(const Value& value);
	bool in(const Value& value);

	int asInt() const;
	double asDouble() const;
	bool asBool() const;
	std::string asString() const;

	/*
		give out a guess, that which type may be more suitable for the value 
		it contains
	 */
	valueType TypeSuggest() const;
	/*
		convert the value it contains to the type more suitable for it 
	*/
	int StringTypeConvert();

	valueType GetType() const;
	void setType(valueType type);

	Value& append(const Value& value);
	Value& append(const char* key, const Value& value);
	Value& append(std::string key, const Value& value);

protected:
	typedef _detail::weakTypeHolder * HolderPtr;

	/*
		holder function
	*/
	void _createHolder();
	void _releaseHolder();
	void _cloneHolder();

	/*
		subclass hooks
	*/
	virtual void _preRead();
	virtual void _preWrite();
	

	HolderPtr holder_;
};



}//namespace weakType
}//namespace wolv


#endif
